package icu.funkye.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import icu.funkye.entity.Test;
import icu.funkye.mapper.TestMapper;
import icu.funkye.service.ITestService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Service
public class TestServiceImpl extends ServiceImpl<TestMapper, Test> implements ITestService {

    @Resource
    private ITestService testService;


    @Override
    @Transactional
    public Object commit() {
        Test t = getOne(Wrappers.<Test>query().select("id", "two").eq("id", 1)
                .last("for update"));
        t.setTwo(t.getTwo() + 1);
        updateById(t);
        return true;
    }

    @Override
    @GlobalTransactional
    public Object commitWrapper() {
        Object commit = testService.commit();
        // TODO: 2021/10/14  模拟分支事务抛出异常
        int i = 1 / 0;
        return commit;
    }

}
